/**************************************************************************/
/*                                                                        */
/* Copyright (c) SinoEmbed Technology Co.,Ltd.           */
/*  */
/*                                                                        */
/*                                                                        */
/*    created:    2012-6-27                                             */ 
/*    filename:   SinoembedPuzzleWnd.cpp                                          */ 
/*    author:     Derek Huang                                                  */  
/*    purpose:                                                            */ 
/*                                                                        */
/* ************************************************************************/
#include "EmptyWnd.h"
#include "ShellWnd.h"
#ifndef MERGER_APP_TO_SHELL
#else
extern CEmptyWnd		* g_pEmptyWnd;
extern HINSTANCE			g_SDHResModuleHandle;
extern DWORD				g_BkgndID;
#endif


CEmptyWnd::CEmptyWnd()
{
}
CEmptyWnd::~CEmptyWnd()
{

}

#ifdef MERGER_APP_TO_SHELL
///////////////////////////////////////////////////////////////////////////
/// For the thread call
/*
BOOL CEmptyWnd::Create()
{
	if(!CMzWndEx::Create(0,0,800,480, 0, 0, 0))
		return FALSE;

	Show(false, false);
	return TRUE;
}
*/
#endif
void CEmptyWnd::PaintWin(HDC hdc, RECT* prcUpdate )
{
	BitBlt(hdc, prcUpdate->left, prcUpdate->top,
		RECT_WIDTH(*prcUpdate), RECT_HEIGHT(*prcUpdate),
		m_hBakDC, prcUpdate->left, prcUpdate->top, SRCCOPY);
	CMzWndEx::PaintWin( hdc, prcUpdate );
}
BOOL CEmptyWnd::OnInitDialog()
{
	if( !CMzWndEx::OnInitDialog() )
	{
		return FALSE;
	}
	LoadiInterItem();
	InitBackgrandImages();
	::SetWindowText(m_hWnd, L"CEmptyWnd");
#ifndef MERGER_APP_TO_SHELL
	SetForegroundWindow( m_hWnd );
#endif
	return TRUE;
}
void CEmptyWnd::LoadiInterItem()
{
//jdhuang 20120818
#ifndef MERGER_APP_TO_SHELL
	m_EmptyWndBG = ImagingHelper::GetImageObject(MzGetInstanceHandle(), 1001);
#else
	m_EmptyWndBG = ImagingHelper::GetImageObject(g_SDHResModuleHandle, g_BkgndID);
#endif


}
BOOL CEmptyWnd::InitBackgrandImages()
{
	HDC hDC = GetDC(m_hWnd);
//jdhuang

	RECT rcClient;
	GetClientRect(m_hWnd, &rcClient);

	m_hBakDC = CreateCompatibleDC(hDC);

	m_hBitmapBakDC = CreateCompatibleBitmap(hDC, RECT_WIDTH(rcClient), RECT_HEIGHT(rcClient));
	SelectObject(m_hBakDC, m_hBitmapBakDC);

	//jdhuang 20090616
//	HDC hMemDc = CreateCompatibleDC(m_hBakDC);

	if(m_EmptyWndBG)
	{
		m_EmptyWndBG->Draw(m_hBakDC, &rcClient, false, false);
//		DeleteDC(hMemDc);
	}
	ReleaseDC(m_hWnd, hDC);

	return TRUE;
}
void CEmptyWnd::DeleteImages()
{
//	SAFE_DELETE_DC(m_hBakDC);
	if(m_hBakDC)
	{ 
		DeleteDC(m_hBakDC);
		m_hBakDC=NULL;
	}

//	SAFE_DELETE_OBJECT(m_hBitmapBakDC);
	if(m_hBitmapBakDC)
	{ 
		DeleteObject(m_hBitmapBakDC);
		m_hBitmapBakDC=NULL;
	}
}
LRESULT CEmptyWnd::MzDefWndProc(UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_CHANGE_BKGND_IMAGE:
		{
			g_BkgndID = LOWORD(wParam);
			ReloadBkgnd();			
			
			if(IsVisible())
				Invalidate();
		}
		break;
	case WM_CHANGE_LANGUAGE:
		{
//			m_UiDesktopIcon.UpdateLanguage();
			break;
		}
		case WM_ENDMODAL_WND:
		{
//			EndModal(ID_CANCEL);
		}
		break;

	}
	return CMzWndEx::MzDefWndProc(message,wParam,lParam);
}
BOOL CEmptyWnd::ReloadBkgnd()
{
	m_EmptyWndBG = ImagingHelper::GetImageObject(g_SDHResModuleHandle, g_BkgndID);
	InitBackgrandImages();
	return TRUE;
}
void CEmptyWnd::OnLButtonDown(UINT fwKeys, int xPos, int yPos)
{
	g_dwScreenIdle = 0;
	CMzWndEx::OnLButtonDown(fwKeys, xPos, yPos);
}
void CEmptyWnd::DestroyWindow()
{
	DeleteImages();
	CMzWnd::DestroyWindow();
}